let bodyWidth = document.body.clientWidth;
let bodyHeight = document.body.clientHeight;
let playerWidth = $(".p1").width() * 0.5;
let playerHeight = $(".p1").height() * 0.5;
//人物移动 179000934 唐国橼
$(".page").click(function(e) {

	$(".p1").stop();
	//获取点击时的坐标
	let x = e.pageX;
	let y = e.pageY;
	//图片的位置坐标
	let pLeft = $(".p1").offset().left + 75;
	let pRight = $(".p1").offset().top;
	//向左向右的图片变化
	if (x > pLeft) {
		$(".p1").attr("src", "img/player_right.gif");
	} else {
		$(".p1").attr("src", "img/player_left.gif");
	}
	//限制移动的边界
	if (x + 150 >= bodyWidth) {
		x = bodyWidth - playerWidth;
	} else if (x < 150) {
		x = playerWidth;
	}
	if (y + 150 >= bodyHeight) {
		y = bodyHeight - playerHeight;
	} else if (y < 150) {
		y = playerHeight;
	}
	//移动动画
	$(".p1").animate({
			left: x - playerWidth,
			top: y - playerHeight
		},
		3000,
		function() {
			$(this).attr("src", "img/player3.gif");
		}

	);

	console.log(x - playerWidth);
});
//双击放大招
$(document).dblclick(function() {
	$(".p1").attr("src", "img/player2.gif");
});
//吃到宝物变身
$(".p2").click(function(e) {
	let thisLeft = $(this).offset().left;
	let thisTop = $(this).offset().top;
	let thisObj = $(this);

	let x = e.pageX;
	let y = e.pageY;

	//等待人物移动至怪物处
	clearId = setTimeout(function() {
		//获取人物图相关信息
		let playerLeft = $(".p1").offset().left + 150;
		let playerTop = $(".p1").offset().top + 150;

		if ((x >= thisLeft && x <= (thisLeft + 150)) && (y >= thisTop && y <= (thisTop + 150))) {
			$(".p1").attr("src", "img/player1_big.gif");
			thisObj.remove();
			let message = "你吃到宝物葫芦<br>人物变身";
			$(".gameInfo").html(message);
			$(".gameInfo").fadeIn(1000, function() {
				$(this).fadeOut(1000);
			})
		} else {
			return;
		}
	}, 3200)
});
